//----------------------------------Include-------------------------------------
#include "mcu.h"
//------------------------------------------------------------------------------

//-----------------------------------Macro--------------------------------------
#define _UART_UNIT               (HPM_UART0)
#define _INT_IRQn                (UART0_INT_IRQn)
//------------------------------------------------------------------------------
#define _DMA_TX                  0
//------------------------------------------------------------------------------
#define _DMA_RX                  0
//------------------------------------------------------------------------------
#define _RXBUF_LEN               (32)
//------------------------------------------------------------------------------

//--------------------------------Static Var------------------------------------
static uint32_t    src_clk;
//------------------------------------------------------------------------------
static uint8_t     rxbuf[_RXBUF_LEN];
//------------------------------------------------------------------------------

//--------------------------------Static Func-----------------------------------
//------------------------------------------------------------------------------

//------------------------------------ISR---------------------------------------
//------------------------------------------------------------------------------

//--------------------------------Public Func-----------------------------------
void mcu_init_uart0(void)
{
//periph clock
  clock_add_to_group(clock_uart0, 0);
  
//pin
  //PY06--U0TX    PY07 -- U0RX
  HPM_IOC->PAD[IOC_PAD_PY07].FUNC_CTL = IOC_PY07_FUNC_CTL_UART0_RXD;
  HPM_IOC->PAD[IOC_PAD_PY06].FUNC_CTL = IOC_PY06_FUNC_CTL_UART0_TXD;
  /* PY port IO needs to configure PIOC as well */
  HPM_PIOC->PAD[IOC_PAD_PY07].FUNC_CTL = PIOC_PY07_FUNC_CTL_SOC_PY_07;
  HPM_PIOC->PAD[IOC_PAD_PY06].FUNC_CTL = PIOC_PY06_FUNC_CTL_SOC_PY_06;
  
//uart
  clock_set_source_divider(clock_uart0, clk_src_osc24m, 1);  /* Configure the UART clock to 24MHz */
  src_clk = clock_get_frequency(clock_uart0);
  
  uart_config_t   cfg;
  uart_default_config(_UART_UNIT, &cfg);
  cfg.src_freq_in_hz   = src_clk;
  cfg.baudrate         = 115200;
  cfg.num_of_stop_bits = 1;
  cfg.word_length      = word_length_8_bits;
  cfg.parity           = parity_none;
  cfg.tx_fifo_level    = uart_tx_fifo_trg_not_full;
  cfg.rx_fifo_level    = uart_rx_fifo_trg_not_empty;
  cfg.dma_enable       = false;
  cfg.fifo_enable      = false;
  uart_init(_UART_UNIT, &cfg);

//interrupt
#if _DMA_RX == 1
  
#else
  
#endif
  

//enable
  
  
#if _DMA_TX == 1
  
#endif

#if _DMA_RX == 1
  
#endif
}

void mcu_uart0_tx(char* p,  uint32_t sz)
{
  uint32_t  i;
  for(i=0; i<sz; i++){
    uart_send_byte(_UART_UNIT, p[i]);
  }
  uart_flush(_UART_UNIT);
}

void mcu_uart0_dma_tx(char* p,  uint32_t sz)
{
#if _DMA_TX == 1
  if(sz > 0){
    
  }
#endif
}
//------------------------------------EOF---------------------------------------




